﻿// <copyright file="SqwareaConfiguration.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Enable you to read configuration AppSettings</summary>

namespace Sqwarea.Web.Misc
{
    using System.Collections.Specialized;
    using System.Configuration;

    /// <summary>
    /// Enable you to read configuration AppSettings.
    /// </summary>
    public static class SqwareaConfiguration
    {
        /// <summary>
        /// Initializes static members of the SqwareaConfiguration class by reading AppSettings configuration.
        /// </summary>
        static SqwareaConfiguration()
        {
            UsePersistenceMock = true;
            ImportData = true;

            // Get the AppSettings section.
            NameValueCollection appSettings =
               ConfigurationManager.AppSettings;

            for (int i = 0; i < appSettings.Count; i++)
            {
                if (appSettings.GetKey(i) == "SqwareaUsePersistenceMock")
                {
                    UsePersistenceMock = bool.Parse(appSettings[i]);
                }
                else if (appSettings.GetKey(i) == "SqwareaImportData")
                {
                    ImportData = bool.Parse(appSettings[i]);
                }
            }
        }

        /// <summary>
        /// Gets a value indicating whether we use mock persistence (SqwareaUsePersistenceMock setting).
        /// This setting is bypassed when we are on the cloud.
        /// </summary>
        public static bool UsePersistenceMock { get; private set; }

        /// <summary>
        /// Gets a value indicating whether we import initial data in the storage (for tests)
        /// (SqwareaImportData setting)
        /// This setting is bypassed when we are on the cloud.
        /// </summary>
        public static bool ImportData { get; private set; }
    }
}
